# backend/schemas.py
from typing import List, Optional
from pydantic import BaseModel, Field,ConfigDict

class DrugBase(BaseModel):
    model_config = ConfigDict(from_attributes=True)   # 👈 关键行
    a25: int = Field(..., description="药品 ID")
    a2:  str = Field(..., description="药品名称")
    a8:  str | None = Field(None, description="生产企业")
    a9:  str | None = Field(None, description="规格")

class DrugListResp(DrugBase):
    pass

class DrugDetailResp(DrugBase):
    ybm: Optional[str] = None
    a29: Optional[str] = None
    a21: Optional[str] = None
    a51: Optional[str] = None
    a53: Optional[str] = None
    pics: List[str] = Field(default_factory=list, description="图片数组")

class PageMeta(BaseModel):
    page: int
    page_size: int
    total: int